package com.tuju.jetpackfirstdemo.ui.link;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.tuju.jetpackfirstdemo.R;
import com.tuju.jetpackfirstdemo.base.baseadapter.BaseRecyclerViewHolder;
import com.tuju.jetpackfirstdemo.base.javabaseadapter.BaseRecyclerViewAdapter2;

import org.jetbrains.annotations.NotNull;

/**
 * Created by 彦泽 on 2018/11/13.
 */

public class TextAdapter extends BaseRecyclerViewAdapter2<String> {
    private TextAdapterCallBack mCallBack;

    public void setCallBack(TextAdapterCallBack callBack) {
        mCallBack = callBack;
    }

    @NonNull
    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_texts, parent, false);
        return new ViewHolder(view);
    }

    class ViewHolder extends BaseRecyclerViewHolder<String>{
        TextView tv_item_text;

        public ViewHolder(@NotNull View view) {
            super(view);
             tv_item_text = view.findViewById(R.id.tv_item_text);

        }

        @Override
        public void onBaseBindViewHolder(final String s, final int position) {
            tv_item_text.setText(s);
            tv_item_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mCallBack != null) {
                        mCallBack.onItemClickCallback(s, position);
                    }
                }
            });
        }
    }

    public interface TextAdapterCallBack {
        void onItemClickCallback(String content, int position);
    }

}
